package com.woniuxy.stage3demo.mapper.otherPzc;

import com.woniuxy.stage3demo.bean.otherPzc.AdsBean;
import com.woniuxy.stage3demo.bean.otherPzc.ApplyForDataConfigBean;
import com.woniuxy.stage3demo.pageHelper.PageRequest;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ApplyForDataConfigMapper {
    /**
     * 新增申请资料
     * @param applyForDataConfig 新增的申请资料对象
     * @return 数据库操作的行数
     */
    @Options(useGeneratedKeys = true,keyProperty = "a.id")
    @Insert("Insert into apply_for_data_config"+
            "(config_name,ready_before,request,attachment,opt_desc,necessary,del_flag)"+
            "values(#{a.configName},#{a.readyBefore},#{a.request},#{a.attachment},#{a.optDesc},#{a.necessary},0)")
    int saveApplyForDataConfig(@Param("a") ApplyForDataConfigBean applyForDataConfig);
    /**
     * 删除申请资料
     * @param id 删除的申请资料对象的id
     * @return 数据库操作的行数
     */
    @Update("update apply_for_data_config set del_flag=1 where id=#{id}")
    int deleteApplyForDataConfig(@Param("id")int id);

    /**
     * 修改申请资料
     * @param applyForDataConfig 修改的申请资料对象
     * @return 操作行数
     */
    @Update("<script>" +
            "update apply_for_data_config" +
            "<set>" +
            "<if test='a.configName != null'>" +
            " config_name = #{a.configName}," +
            "</if>" +
            "<if test='a.readyBefore != null'>" +
            " ready_before = #{a.readyBefore}," +
            "</if>" +
            "<if test='a.request != null'>" +
            " request = #{a.request}," +
            "</if>" +
            "<if test='a.attachment != null'>" +
            " attachment = #{a.attachment}," +
            "</if>" +
            "<if test='a.optDesc != null'>" +
            " opt_desc = #{a.optDesc}," +
            "</if>" +
            "<if test='a.necessary != null'>" +
            " necessary = #{a.necessary}," +
            "</if>" +
            "</set>" +
            "where id = #{a.id}" +
            "</script>")
    int updateApplyForDataConfig(@Param("a") ApplyForDataConfigBean applyForDataConfig);


    List<AdsBean> findAllByParams(@Param("p") PageRequest request, @Param("a")ApplyForDataConfigBean applyForDataConfig);
}
